/*
 +-----------------------------------------------------------------------------------------------+
 | Project : UKAPI
 +-----------------------------------------------------------------------------------------------+
 | Project Description : Universal & Kernel API
 +-----------------------------------------------------------------------------------------------+
 | File Description :
 |   Debug API
 |                                                 
 +-----------------------------------------------------------------------------------------------+
 | Licence : MIT Licence
 +-----------------------------------------------------------------------------------------------+
 | Copyright (c) 2006 Olivier Vanhoucke
 | 
 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 | and associated documentation files (the "Software"), to deal in the Software without 
 | restriction, including without limitation the rights to use, copy, modify, merge, publish, 
 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 
 | Software is furnished to do so, subject to the following conditions:
 | 
 | The above copyright notice and this permission notice shall be included in all copies or 
 | substantial portions of the Software.
 | 
 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 +-----------------------------------------------------------------------------------------------+
*/

#ifndef __UKAPI_KERNEL_EVENT__
#define __UKAPI_KERNEL_EVENT__

typedef struct
{
	bool_t			manual_reset;
	bool_t			state;
	string_ascii_t	name;
	callback_t		callback;

#if		( CPU_ARCHITECTURE == CPU_ARCHITECTURE_WIN32 )
	HANDLE			event;
#elif	( CPU_ARCHITECTURE == CPU_ARCHITECTURE_POSIX )
	pthread_event_t	event;
#else
	long_t			event;	// ?
	list_t			listeners; // ptask_t
#endif
} event_t, * pevent_t;

#ifdef __cplusplus
	extern "C" {
#endif /* __cplusplus */

pevent_t event_create( bool_t manual_reset, bool_t initial_state, string_ascii_t name, callback_t callback );
pevent_t event_open( string_ascii_t name );
result_t event_set( pevent_t pevent );
result_t event_reset( pevent_t pevent );
result_t event_pulse( pevent_t pevent );
result_t event_wait( pevent_t pevent, timeout_t timeout );
result_t event_receive( pevent_t pevent );
result_t event_destroy( pevent_t pevent );


//int _receive_event( priority_queue_t evts, const pevent_t evt );
//int _process_event( priority_queue_t evts, int (*aiguiller)( pevent_t evt ) );

#ifdef __cplusplus
	}
#endif /* __cplusplus */

#endif /* __UKAPI_KERNEL_EVENT__ */
